﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using QzEbook.AccessObject;
using System.Collections.Generic;
using System.Text;
using QzEbook.Common;




public enum UserListType
{

    Default = 0x02,
    Search = 0x04,
    Other = 0x08
}

public partial class module_userList : System.Web.UI.UserControl
{
    private StringBuilder sb;
    private string keyword = string.Empty;
    private UserListType type = UserListType.Default;

    public UserListType Type
    {
        get { return type; }
        set { type = value; }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        BindData();
    }

    private void BindData()
    {
        UserList userlist = new UserList();
        List<SiteUser> list = null;
        switch (type)
        {
            case UserListType.Default:
                list = userlist.selectList();
                break;
            case UserListType.Search:
                keyword = Request["Key"] as string;
                if (!string.IsNullOrEmpty(keyword))
                {
                    userlist.KeyWord = keyword;
                    list = userlist.SearchUser();
                }
                break;
            case UserListType.Other:
                break;
            default:
                break;
        }




        sb = new StringBuilder();
        sb.Append("<ul id='userList'>");


        if (list==null || list.Count==0)
        {
            sb.Append("<li><h3>不存在用户</h3></li>");
            sb.Append("</ul>");
            return;
        }


        foreach (SiteUser item in list)
        {
            sb.Append("<li>");
            sb.AppendFormat("<a href=\"user.xhtml?Uid={0}\" title=\"进入此用户电子书页面\">", item.Uid);
            sb.AppendFormat("<img src=\"{0}\" title=\"头像\" />", Config.UserBookSavePath + "noset.gif");
            sb.Append("<ins>");
            sb.AppendFormat("<h3 title=\"userName\">用户: {0}</h3>", item.Name);
            sb.AppendFormat("<dd>等级: {0}</dd>", item.LevelName);
            sb.AppendFormat("<dd title=\"email\">邮件: {0}</dd>", item.Mail);
            sb.AppendFormat("<dd>QQ: {0}</dd>", item.Qq);

            sb.AppendFormat("<dd>书数: {0}</dd>", item.GrossBooks);
            sb.Append("</ins>");
            sb.Append("</a>");
            sb.Append("</li>");
        }

        sb.Append("</ul>");
    }


    protected override void Render(HtmlTextWriter writer)
    {
        if (sb != null)
        {
            writer.Write(sb.ToString());
        }
        base.Render(writer);
    }
}
